// Learn cc.Class:
//  - https://docs.cocos.com/creator/manual/en/scripting/class.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

cc.Class({
    extends: cc.Component,

    properties: {
   
    },

    onLoad () {
        // 开启碰撞检测，开启调试模式（绘制碰撞器形状）
        cc.director.getCollisionManager().enabled = true;
        cc.director.getCollisionManager().enabledDebugDraw = true;
        this.touchingNumber = 0;
    },

    // update (dt) {},
    // 监听碰撞事件
    onCollisionEnter(other, self) {
        // 获取碰撞的节点
        let node = other.node;
        // 获取碰撞的节点的标签
        let tag = node.tag;
        // 获取碰撞的节点的标签
        let name = node.name;
        // 获取碰撞的节点的标签
        let type = node.type;
        // 获取碰撞的节点的标签
        let uuid = node.uuid;
        this.node.color = cc.Color.RED;
        console.log("碰撞进入：" + this.node.name, other.node.name);
        this.touchingNumber++;
    },
    /**
     * 当物体在碰撞期间持续与另一个物体碰撞时调用此方法。
     *
     * @param other 碰撞的另一个物体
     * @param self 当前物体
     */
    onCollisionStay(other, self) {
        console.log("碰撞中:", other.node.name);
    },
    onCollisionExit(other, self) {
        console.log("离开:", other.node.name);
        this.touchingNumber--;
        if(this.touchingNumber == 0){
            this.node.color = cc.Color.WHITE;
        }
    }


});
